#include "header_widget.h"
#include "ui_header_widget.h"

#define BUTTON "color:rgb(255,255,255);\n background-color: rgb(76,76,76);\n  border-radius: 5px;"
#define BUTTON_LEFT "color:rgb(255,255,255);\n background-color: rgb(76,76,76);\n  border-top-left-radius: 5px;\n  border-bottom-left-radius: 5px;"
#define BUTTON_MIDLLE "color:rgb(255,255,255);\n background-color: rgb(76,76,76);\n border: 1px;"
#define BUTTON_RIGHT "color:rgb(255,255,255);\n background-color: rgb(76,76,76);\n  border-top-right-radius: 5px;\n  border-bottom-right-radius: 5px;"
#define BUTTON_SELECTED "background-color: #808080;"

HeaderWidget::HeaderWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::HeaderWidget),
    operateType(OT_PAGE1)
{
    ui->setupUi(this);

    ui->horizontalLayoutMiddle->setAlignment(Qt::AlignLeft);
    ui->horizontalLayoutMiddle->setSpacing(1);
    ui->horizontalLayoutRight->setAlignment(Qt::AlignRight);

    ui->pushButtonPage1->setFixedSize(QSize(70, 30));
    ui->pushButtonPage1->setStyleSheet(QString(BUTTON_LEFT).append(BUTTON_SELECTED));

    ui->pushButtonPage2->setFixedSize(QSize(70, 30));
    ui->pushButtonPage2->setStyleSheet(BUTTON_MIDLLE);

    ui->pushButtonPage3->setFixedSize(QSize(70, 30));
    ui->pushButtonPage3->setStyleSheet(BUTTON_MIDLLE);

    ui->pushButtonPage4->setFixedSize(QSize(70, 30));
    ui->pushButtonPage4->setStyleSheet(BUTTON_RIGHT);

    ui->pushButtonUser->setFixedSize(QSize(70, 30));
    ui->pushButtonUser->setStyleSheet(BUTTON);

    connect(ui->pushButtonPage1, SIGNAL(clicked()), this, SLOT(on_pushButtonPage1Clicked()));
    connect(ui->pushButtonPage2, SIGNAL(clicked()), this, SLOT(on_pushButtonPage2Clicked()));
    connect(ui->pushButtonPage3, SIGNAL(clicked()), this, SLOT(on_pushButtonPage3Clicked()));
    connect(ui->pushButtonPage4, SIGNAL(clicked()), this, SLOT(on_pushButtonPage4Clicked()));
    connect(ui->pushButtonUser, SIGNAL(clicked()), this, SLOT(on_pushButtonUserClicked()));
}

HeaderWidget::~HeaderWidget()
{
    delete ui;
}

void HeaderWidget::setOperateType(OperateType type) {
    operateType = type;
}

HeaderWidget::OperateType HeaderWidget::getOperateType() const {
    return operateType;
}

void HeaderWidget::on_pushButtonPage1Clicked() {
    emit operateChange(OT_PAGE1);
    ui->pushButtonPage1->setStyleSheet(QString(BUTTON_LEFT).append(BUTTON_SELECTED));
    ui->pushButtonPage2->setStyleSheet(QString(BUTTON_MIDLLE));
    ui->pushButtonPage3->setStyleSheet(QString(BUTTON_MIDLLE));
    ui->pushButtonPage4->setStyleSheet(QString(BUTTON_RIGHT));
}

void HeaderWidget::on_pushButtonPage2Clicked() {
    emit operateChange(OT_PAGE2);
    ui->pushButtonPage1->setStyleSheet(QString(BUTTON_LEFT));
    ui->pushButtonPage2->setStyleSheet(QString(BUTTON_MIDLLE).append(BUTTON_SELECTED));
    ui->pushButtonPage3->setStyleSheet(QString(BUTTON_MIDLLE));
    ui->pushButtonPage4->setStyleSheet(QString(BUTTON_RIGHT));
}

void HeaderWidget::on_pushButtonPage3Clicked() {
    emit operateChange(OT_PAGE3);
    ui->pushButtonPage1->setStyleSheet(QString(BUTTON_LEFT));
    ui->pushButtonPage2->setStyleSheet(QString(BUTTON_MIDLLE));
    ui->pushButtonPage3->setStyleSheet(QString(BUTTON_MIDLLE).append(BUTTON_SELECTED));
    ui->pushButtonPage4->setStyleSheet(QString(BUTTON_RIGHT));
}

void HeaderWidget::on_pushButtonPage4Clicked() {
    emit operateChange(OT_PAGE4);
    ui->pushButtonPage1->setStyleSheet(QString(BUTTON_LEFT));
    ui->pushButtonPage2->setStyleSheet(QString(BUTTON_MIDLLE));
    ui->pushButtonPage3->setStyleSheet(QString(BUTTON_MIDLLE));
    ui->pushButtonPage4->setStyleSheet(QString(BUTTON_RIGHT).append(BUTTON_SELECTED));
}

void HeaderWidget::on_pushButtonUserClicked() {
    qApp->quit();
}
